// 未通过
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
ll p(ll x, ll k) {
  ll ans = 1;
  while (k > 0) {
    if (k % 2 == 1) {
      (ans *= x) %= mod;
    }
    (x *= x) %= mod;
    k /= 2;
  }
  return ans;
}
int main() {
  ll n, m;
  cin >> n >> m;
  cout << (m * p(m - 1, n - 1) % mod + mod) % mod;
  return 0;
}